<template>
	<div>
		<div class="searchWord">

			<el-form :inline="true" class="demo-form-inline">
				<el-form-item label="状态">
					<el-select clearable v-model="listWareHouseParam.shopStatus" placeholder="请选择">
						<el-option label="启用" value="0">
						</el-option>
						<el-option label="禁用" value="1">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="模糊条件">
					<el-input style="width: 200px;" placeholder="请输入内容" v-model="listWareHouseParam.keyword" clearable>
					</el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" round="true" @click="loadhouse(1)">查询</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="success" round="true" @click="openAdd ">添加</el-button>
				</el-form-item>
				<el-form-item>
					<el-button :disabled="ids.length <= 0" type="danger" @click="delShop">删除</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="success" round="true" @click="openUpdate">修改</el-button>
				</el-form-item>
			</el-form>
		</div>


		<div>
			<el-table :data="house" @selection-change="getChecks">
				<el-table-column type="selection" label="序号">
				</el-table-column>
				<el-table-column prop="warehouseId" label="序号">
				</el-table-column>
				<el-table-column prop="warehouseName" label="仓库名称">
				</el-table-column>
				<el-table-column prop="warehouseLinkman" label="联系人">
				</el-table-column>
				<el-table-column prop="warehousePhone" label="手机号">
				</el-table-column>
				<el-table-column prop="warehouseAddress" label="地址">
				</el-table-column>
				<el-table-column prop="shopName" label="关联门店">
				</el-table-column>
				<el-table-column label="状态">
					<template slot-scope="scope">
						{{ scope.row.warehouseStatus == 1 ? '停用' : '启用' }}
					</template>
				</el-table-column>
			</el-table>
		</div>
		<div>
			<el-pagination :page-sizes="sizes" @size-change="sizeChangeFind"
				:current-page="listWareHouseParam.indexPage" @current-change="changePage" background
				layout="sizes, prev, pager, next" :total="total" :page-size="listWareHouseParam.pageSize">
			</el-pagination>
		</div>
		<el-dialog @close="clearAddForm" title="新增仓库" :visible.sync="addMovieVisible">
			<div>
				<el-form>
					<el-form-item label="仓库名称">
						<el-input v-model="saveShopParam.warehouseName"></el-input>
					</el-form-item>
					<el-form-item label="联系人">
						<el-input v-model="saveShopParam.warehouseLinkman"></el-input>
					</el-form-item>
					<el-form-item label="电话">
						<el-input v-model="saveShopParam.warehousePhone"></el-input>
					</el-form-item>
					<el-form-item label="地址">
						<el-input v-model="saveShopParam.warehouseAddress"></el-input>
					</el-form-item>
					<el-form-item label="状态">
						<template>
							<el-radio v-model="saveShopParam.warehouseStatus" label="0">启用</el-radio>
							<el-radio v-model="saveShopParam.warehouseStatus" label="1">停用</el-radio>
						</template>
					</el-form-item>
				</el-form>
			</div>

			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="saveShop">提 交</el-button>
			</div>
		</el-dialog>
		<el-dialog @close="clearUpForm" title="修改仓库" :visible.sync="UpdateVisible">
			<div>
				<el-form>
					<el-form-item label="门店名称">
						<el-input v-model="updateShopParam.warehouseName"></el-input>
					</el-form-item>
					<el-form-item label="联系人">
						<el-input v-model="updateShopParam.warehouseLinkman"></el-input>
					</el-form-item>
					<el-form-item label="电话">
						<el-input v-model="updateShopParam.warehousePhone"></el-input>
					</el-form-item>
					<el-form-item label="地址">
						<el-input v-model="updateShopParam.warehouseAddress"></el-input>
					</el-form-item>
					<el-form-item label="关联门店">
						<el-input :disabled="true" v-model="updateShopParam.shopName"></el-input>
					</el-form-item>
					<el-form-item label="状态">
						<el-radio-group v-model="updateShopParam.warehouseStatus">
							<el-radio :label="0">启用</el-radio>
							<el-radio :label="1">停用</el-radio>
						</el-radio-group>

					</el-form-item>

				</el-form>
			</div>

			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="Update">提 交</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				listWareHouseParam: {
					indexPage: 1,
					pageSize: 3,
					keyword: null,
					warehouseStatus: null
				},
				total: 0,
				sizes: [1, 2, 3, 5, 10, 20],
				house: [],
				ids: [],
				addMovieVisible: false,
				UpdateVisible: false,
				saveShopParam: {
					warehouseName: null,
					warehouseLinkman: null,
					warehousePhone: null,
					warehouseAddress: null,
					warehouseStatus: null,
				},
				updateShopParam: {
					warehouseName: null,
					warehouseLinkman: null,
					warehousePhone: null,
					warehouseAddress: null,
					warehouseStatus: null,
					shopName: null
				}
			}
		},

		methods: {
			loadhouse(page) {
				if (page != undefined) {
					this.listWareHouseParam.indexPage = page;
				}
				this.$http.post("/warehouse-table/listWareHouse", this.listWareHouseParam).then(resp => {
					if (resp.data.code == 200) {
						this.house = resp.data.data.warehouseDtoList;
						this.total = resp.data.data.total;
						this.listWareHouseParam.indexPage = resp.data.data.indexPage;
					} else {
						this.$message({
							type: 'error',
							message: '查询失败 ' + resp.data.msg
						});
					}


				})
			},
			getChecks(sel) {
				this.ids = [];
				for (let i = 0; i < sel.length; i++) {
					this.ids.push(sel[i].warehouseId);
				}
			},
			sizeChangeFind(size) {
				this.listWareHouseParam.pageSize = size;
				this.loadhouse();
			},
			changePage(page) {
				this.listWareHouseParam.indexPage = page;
				this.loadhouse();
			},
			delShop() {
				if (this.ids.length > 0) {
					this.$http.post("/warehouse-table/delWarehouse", this.ids).then(resp => {
						if (resp.data.code == 200) {
							this.$message({
								message: '删除成功',
								type: 'success'
							});
							this.loadhouse();
						} else {
							this.$message({
								type: 'error',
								message: '删除失败 ' + resp.data.msg
							});
						}
					})
				}
			},
			saveShop() {
				this.$http.post("/warehouse-table/SaveWarehouse", this.saveShopParam).then(resp => {
					if (resp.data.code == 200) {
						this.addMovieVisible = !this.addMovieVisible;
						this.$message({
							message: '添加成功',
							type: 'success',

						});
						this.loadhouse();
						this.clearAddForm();

					} else {
						this.$message({
							type: 'error',
							message: '添加失败 ' + resp.data.msg
						});
					}
				})
			},
			openAdd() {
				this.addMovieVisible = !this.addMovieVisible;
			},

			clearAddForm() {
				this.saveShopParam = {
					warehouseName: null,
					warehouseLinkman: null,
					warehousePhone: null,
					warehouseAddress: null,
					warehouseStatus: null,
				}
			},
			clearUpForm() {
				this.updateShopParam = {
					warehouseName: null,
					warehouseLinkman: null,
					warehousePhone: null,
					warehouseAddress: null,
					warehouseStatus: null,
				}
			},
			Update() {
				this.$http.post("/warehouse-table/updateWarehouse", this.updateShopParam).then(resp => {
					if (resp.data.code == 200) {
						this.$message({
							message: '更新成功',
							type: 'success'
						});

					} else {
						this.$message({
							type: 'error',
							message: '更新失败 ' + resp.data.msg
						});

					}
					this.clearUpForm();
					this.UpdateVisible = !this.UpdateVisible;
					this.loadhouse();
				})

			},
			openUpdate() {
				if (!this.UpdateVisible) {
					if (this.ids.length <= 0 || this.ids.length > 1) {
						alert("选择错误")
						return;
					}
				}
				this.UpdateVisible = !this.UpdateVisible;
				if (this.UpdateVisible) {
					this.$http.get("/warehouse-table/gethouse/" + this.ids[0]).then(resp => {
						this.updateShopParam = resp.data.data;
					})
				}
			}
		},
		created() {
			this.loadhouse();

		}
	}
</script>

<style>
</style>
